package com.xbongbong.admin.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.admin.pojo.dto.MirrorChartPreviewDTO;
import com.xbongbong.admin.pojo.dto.MirrorInstallAllDTO;
import com.xbongbong.admin.pojo.dto.MirrorInstallDTO;
import com.xbongbong.admin.pojo.dto.MirrorInstructionAllDTO;
import com.xbongbong.admin.pojo.dto.MirrorInstructionDTO;
import com.xbongbong.admin.pojo.dto.MirrorMenuListAllDTO;
import com.xbongbong.admin.pojo.dto.MirrorMenuListDTO;
import com.xbongbong.admin.pojo.dto.MirrorPreviewDTO;
import com.xbongbong.admin.pojo.vo.MirrorChartListAllVO;
import com.xbongbong.admin.pojo.vo.MirrorChartListVO;
import com.xbongbong.admin.pojo.vo.MirrorChartPojoVO;
import com.xbongbong.admin.pojo.vo.MirrorChartPreviewVO;
import com.xbongbong.admin.pojo.vo.MirrorInstallAllVO;
import com.xbongbong.admin.pojo.vo.MirrorInstallVO;
import com.xbongbong.admin.pojo.vo.MirrorInstructionAllVO;
import com.xbongbong.admin.pojo.vo.MirrorInstructionVO;
import com.xbongbong.admin.pojo.vo.MirrorMenuListVO;
import com.xbongbong.admin.pojo.vo.MirrorPreviewVO;
import com.xbongbong.admin.pojo.vo.MirrorResultChartVO;
import com.xbongbong.admin.pojo.vo.MirrorSystemMenuListVO;
import com.xbongbong.admin.pojo.vo.MirrorWorkOrderListVO;
import com.xbongbong.admin.service.MirrorConfigService;
import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.domain.entity.PaasFormExplainEntity;
import com.xbongbong.paas.enums.DelEnum;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.manager.feign.MirrorFeignClent;
import com.xbongbong.paas.model.PaasFormExplainModel;
import com.xbongbong.paas.redis.PaasRedisHelper;
import com.xbongbong.paas.redis.RedisConstant;
import com.xbongbong.paas.redis.RedisPrefixConstant;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.DateUtil;
import com.xbongbong.paas.toolbox.util.StringUtil;
import com.xbongbong.paas.toolbox.wrap.XbbResponse;
import com.xbongbong.pro.domain.entity.AppModuleEntity;
import com.xbongbong.pro.enums.ErrorCodeEnum;
import com.xbongbong.pro.enums.errorcodes.StatisticsServicesErrorCodeEnum;
import com.xbongbong.pro.enums.errorcodes.TemplateCenterErrorCodeEnum;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.script.pojo.dto.MirrorDeleteAttrDTO;
import com.xbongbong.pro.script.pojo.dto.MirrorUpdateAttrDTO;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.model.AppModuleModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;

/**
 * 镜像功能
 * @author xingxing.xiao
 */
@Service("mirrorConfigService")
public class MirrorConfigServiceImpl implements MirrorConfigService {
    private static final Logger LOG = LoggerFactory.getLogger(MirrorConfigServiceImpl.class);

    @Resource
    private MirrorFeignClent mirrorFeignClent;
    @Resource
    private AppModuleModel appModuleModel;
    @Resource
    private PaasRedisHelper paasRedisHelper;
    @Resource
    private PaasFormExplainModel paasFormExplainModel;

    /**
     * 镜像安装
     * @param mirrorInstallDTO
     * @return
     * @throws XbbException
     * @author xingxing.xiao
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public MirrorInstallVO install(MirrorInstallDTO mirrorInstallDTO) throws XbbException {
        MirrorInstallVO mirrorInstallVO = new MirrorInstallVO();
        try {
            Locale locale = LocaleContextHolder.getLocale();
            String lang = locale.toString();
            XbbResponse<MirrorInstallVO> installResp = mirrorFeignClent.install(mirrorInstallDTO, lang);
            if (installResp.isSuccess()) {
                return mirrorInstallVO;
            } else {
                throw new XbbException(installResp.getCode(), installResp.getMsg());
            }
        } catch (XbbException e){
            throw e;
        } catch (Exception e) {
            LOG.error("mirror install error", e);
            throw new XbbException(StatisticsServicesErrorCodeEnum.API_ERROR_224011, String.format(StatisticsServicesErrorCodeEnum.API_ERROR_224011.getMsg(), "镜像应用安装出错"));
        }
    }

    /**
     * 组合镜像安装
     * @param mirrorInstallAllDTO
     * @return
     * @throws XbbException
     * @author youli.chen
     */
    @Override
    public MirrorInstallAllVO installAll(MirrorInstallAllDTO mirrorInstallAllDTO) throws XbbException {
        MirrorInstallAllVO mirrorInstallAllVO = new MirrorInstallAllVO();
        try {
            Locale locale = LocaleContextHolder.getLocale();
            String lang = locale.toString();
            XbbResponse<MirrorInstallAllVO> installResp = mirrorFeignClent.installAll(mirrorInstallAllDTO, lang);
            if (installResp.isSuccess()) {
                mirrorInstallAllVO.setInstallable(1);
                return mirrorInstallAllVO;
            } else {
                throw new XbbException(installResp.getCode(), installResp.getMsg());
            }
        } catch (XbbException e){
            throw e;
        } catch (Exception e) {
            LOG.error("mirror installAll error", e);
            throw new XbbException(StatisticsServicesErrorCodeEnum.API_ERROR_224011, String.format(StatisticsServicesErrorCodeEnum.API_ERROR_224011.getMsg(), "镜像应用安装出错"));
        }
    }

    /**
     * 镜像菜单列表
     * @param mirrorMenuListDTO
     * @return
     * @throws XbbException
     * @author xingxing.xiao
     */
    @Override
    public MirrorMenuListVO getMenuList(MirrorMenuListDTO mirrorMenuListDTO) throws XbbException {
        Locale locale = LocaleContextHolder.getLocale();
        String lang = locale.toString();
        XbbResponse<MirrorMenuListVO> response = mirrorFeignClent.getMenuList(mirrorMenuListDTO, lang);
        if (response.isSuccess()) {
            return response.getResult();
        } else {
            throw new XbbException(response.getCode(), response.getMsg());
        }
    }

    /**
     * 组合镜像菜单列表
     * @param mirrorMenuListDTO
     * @return
     * @throws XbbException
     * @author youli.chen
     */
    @Override
    public MirrorMenuListVO getMenuListAll(MirrorMenuListAllDTO mirrorMenuListDTO) throws XbbException {
        Locale locale = LocaleContextHolder.getLocale();
        String lang = locale.toString();
        XbbResponse<MirrorMenuListVO> response = mirrorFeignClent.getMenuListAll(mirrorMenuListDTO, lang);
        if (response.isSuccess()) {
            return response.getResult();
        } else {
            throw new XbbException(response.getCode(), response.getMsg());
        }
    }

    /**
     * 表单镜像列表（展示菜单 - 表单）
     * @param mirrorMenuListDTO
     * @return
     * @throws XbbException
     * @author xingxing.xiao
     */
    @Override
    public MirrorSystemMenuListVO getSystemFormList(MirrorMenuListDTO mirrorMenuListDTO) throws XbbException {
        Locale locale = LocaleContextHolder.getLocale();
        String lang = locale.toString();
        XbbResponse<MirrorSystemMenuListVO> response = mirrorFeignClent.getSystemFormList(mirrorMenuListDTO, lang);
        if (response.isSuccess()) {
            return response.getResult();
        } else {
            throw new XbbException(response.getCode(), response.getMsg());
        }
    }

    /**
     * 组合表单镜像列表（展示菜单 - 表单）
     * @param mirrorMenuListAllDTO
     * @return
     * @throws XbbException
     * @author xingxing.xiao
     */
    @Override
    public MirrorSystemMenuListVO getSystemFormListAll(MirrorMenuListAllDTO mirrorMenuListAllDTO) throws XbbException {
        Locale locale = LocaleContextHolder.getLocale();
        String lang = locale.toString();
        XbbResponse<MirrorSystemMenuListVO> response = mirrorFeignClent.getSystemFormListAll(mirrorMenuListAllDTO, lang);
        if (response.isSuccess()) {
            return response.getResult();
        } else {
            throw new XbbException(response.getCode(), response.getMsg());
        }
    }

    /**
     * 工单镜像列表
     * @param mirrorMenuListDTO
     * @return
     * @throws XbbException
     * @author xingxing.xiao
     */
    @Override
    public MirrorWorkOrderListVO getWorkOrderList(MirrorMenuListDTO mirrorMenuListDTO) throws XbbException {
        Locale locale = LocaleContextHolder.getLocale();
        String lang = locale.toString();
        XbbResponse<MirrorWorkOrderListVO> response = mirrorFeignClent.getWorkOrderList(mirrorMenuListDTO, lang);
        if (response.isSuccess()) {
            return response.getResult();
        } else {
            throw new XbbException(response.getCode(), response.getMsg());
        }
    }

    /**
     * 组合工单镜像列表
     * @param mirrorMenuListDTO
     * @return
     * @throws XbbException
     * @author xingxing.xiao
     */
    @Override
    public MirrorWorkOrderListVO getWorkOrderListAll(MirrorMenuListAllDTO mirrorMenuListDTO) throws XbbException {
        Locale locale = LocaleContextHolder.getLocale();
        String lang = locale.toString();
        XbbResponse<MirrorWorkOrderListVO> response = mirrorFeignClent.getWorkOrderListAll(mirrorMenuListDTO, lang);
        if (response.isSuccess()) {
            return response.getResult();
        } else {
            throw new XbbException(response.getCode(), response.getMsg());
        }
    }

    /**
     * 图表镜像列表
     * @param mirrorMenuListDTO
     * @return
     * @throws XbbException
     * @author xingxing.xiao
     */
    @Override
    public MirrorChartListVO getChartList(MirrorMenuListDTO mirrorMenuListDTO) throws XbbException {
        Locale locale = LocaleContextHolder.getLocale();
        String lang = locale.toString();
        XbbResponse<MirrorChartListVO> response = mirrorFeignClent.getChartList(mirrorMenuListDTO, lang);
        if (response.isSuccess()) {
            return response.getResult();
        } else {
            throw new XbbException(response.getCode(), response.getMsg());
        }
    }

    /**
     * 组合图表镜像列表
     * @param mirrorMenuListDTO
     * @return
     * @throws XbbException
     * @author xingxing.xiao
     */
    @Override
    public MirrorChartListAllVO getChartListAll(MirrorMenuListAllDTO mirrorMenuListDTO) throws XbbException {
        Locale locale = LocaleContextHolder.getLocale();
        String lang = locale.toString();
        XbbResponse<MirrorChartListAllVO> response = mirrorFeignClent.getChartListAll(mirrorMenuListDTO, lang);
        if (response.isSuccess()) {
            return response.getResult();
        } else {
            throw new XbbException(response.getCode(), response.getMsg());
        }
    }

    /**
     * 镜像图表预览
     * @param mirrorChartPreviewDTO
     * @return
     * @throws XbbException
     * @author xingxing.xiao
     */
    @Override
    public MirrorChartPreviewVO getChartPreview(MirrorChartPreviewDTO mirrorChartPreviewDTO) throws XbbException {
        Locale locale = LocaleContextHolder.getLocale();
        String lang = locale.toString();
        XbbResponse<MirrorChartPreviewVO> response = mirrorFeignClent.getChartPreview(mirrorChartPreviewDTO, lang);
        if (response.isSuccess()) {
            MirrorChartPreviewVO result = response.getResult();
            List<MirrorChartPojoVO> chartList = result.getChartList();
            chartList.forEach(item -> {
                List<MirrorResultChartVO> charts = item.getChartData().getChart();
                if (Objects.nonNull(charts)) {
                    charts.forEach(chart -> {
                        chart.setXAxis(chart.getBackXaxis());
                        chart.setXAxisKeys(chart.getBackXaxisKeys());
                        chart.setBackXaxis(null);
                        chart.setBackXaxisKeys(null);
                    });
                }
            });
            result.setChartList(chartList);
            return result;
        } else {
            throw new XbbException(response.getCode(), response.getMsg());
        }
    }

    /**
     * 镜像表单预览
     * @param mirrorPreviewDTO
     * @return
     * @throws XbbException
     * @author xingxing.xiao
     */
    @Override
    public MirrorPreviewVO preview(MirrorPreviewDTO mirrorPreviewDTO) throws XbbException {
        Locale locale = LocaleContextHolder.getLocale();
        String lang = locale.toString();
        XbbResponse<MirrorPreviewVO> response = mirrorFeignClent.preview(mirrorPreviewDTO, lang);
        if (response.isSuccess()) {
            return response.getResult();
        } else {
            throw new XbbException(response.getCode(), response.getMsg());
        }
    }

    /**
     * 镜像应用信息
     * @throws XbbException
     * @author xingxing.xiao
     */
    @Override
    public MirrorInstructionVO getMirrorInstruction(MirrorInstructionDTO mirrorInstructionDTO) throws XbbException {
        MirrorInstructionVO instructionVO = new MirrorInstructionVO();
        Long mirrorId = mirrorInstructionDTO.getMirrorId();
        String corpid = mirrorInstructionDTO.getCorpid();
        try {
            // 此处是模板中心的逻辑
            if (Objects.nonNull(mirrorInstructionDTO.getModule()) && mirrorInstructionDTO.getModule()) {
                AppModuleEntity entity = appModuleModel.getByMirrorId(mirrorId);
                if (entity == null) {
                    throw new XbbException(TemplateCenterErrorCodeEnum.API_ERROR_402005, TemplateCenterErrorCodeEnum.API_ERROR_402005.getMsg());
                }
                if (Objects.equals(entity.getShelves(), 0)) {
                    throw new XbbException(TemplateCenterErrorCodeEnum.API_ERROR_402006, TemplateCenterErrorCodeEnum.API_ERROR_402006.getMsg());
                }
                instructionVO.setAppModuleId(entity.getId());
                if (entity.getNewApp() == 1 && DateUtil.getInt() - entity.getAddTime() < RedisConstant.HUGE_DURATION) {
                    String key = entity.getId() + corpid + mirrorInstructionDTO .getUserId();
                    String value = paasRedisHelper.getValue(RedisPrefixConstant.APP_NEW_LABEL_KEY, key);
                    if (StringUtil.isEmpty(value)) {
                        paasRedisHelper.setValue(RedisPrefixConstant.APP_NEW_LABEL_KEY, key, 1, RedisConstant.HUGE_DURATION);
                    }
                }
            }

            Locale locale = LocaleContextHolder.getLocale();
            String lang = locale.toString();
            XbbResponse<MirrorInstructionVO> response = mirrorFeignClent.getMirrorInstruction(mirrorInstructionDTO, lang);
            if (response.isSuccess()) {
                return response.getResult();
            } else {
                throw new XbbException(response.getCode(), response.getMsg());
            }
        } catch (XbbException e) {
            throw e;
        } catch (Exception e) {
            LOG.error("getMirrorInstruction error: ", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
    }

    @Override
    public MirrorInstructionAllVO getMirrorInstructionAll(MirrorInstructionAllDTO mirrorInstructionAllDTO) throws XbbException {
        Long appModuleId = mirrorInstructionAllDTO.getAppModuleId();
        String corpid = mirrorInstructionAllDTO.getCorpid();
        try {
            // 此处是模板中心的逻辑
            if (Objects.nonNull(mirrorInstructionAllDTO.getModule()) && mirrorInstructionAllDTO.getModule()) {
                AppModuleEntity entity = appModuleModel.getByKey(appModuleId);
                if (entity == null) {
                    throw new XbbException(TemplateCenterErrorCodeEnum.API_ERROR_402005);
                }
                if (Objects.equals(entity.getShelves(), 0)) {
                    throw new XbbException(TemplateCenterErrorCodeEnum.API_ERROR_402006);
                }
                if (entity.getNewApp() == 1 && DateUtil.getInt() - entity.getAddTime() < RedisConstant.HUGE_DURATION) {
                    String key = entity.getId() + corpid + mirrorInstructionAllDTO .getUserId();
                    String value = paasRedisHelper.getValue(RedisPrefixConstant.APP_NEW_LABEL_KEY, key);
                    if (StringUtil.isEmpty(value)) {
                        paasRedisHelper.setValue(RedisPrefixConstant.APP_NEW_LABEL_KEY, key, 1, RedisConstant.HUGE_DURATION);
                    }
                }
            }

            Locale locale = LocaleContextHolder.getLocale();
            String lang = locale.toString();
            XbbResponse<MirrorInstructionAllVO> response = mirrorFeignClent.getMirrorInstructionAll(mirrorInstructionAllDTO, lang);
            if (response.isSuccess()) {
                return response.getResult();
            } else {
                throw new XbbException(response.getCode(), response.getMsg());
            }
        } catch (XbbException e) {
            throw e;
        } catch (Exception e) {
            LOG.error("getMirrorInstructionAll error: ", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001);
        }
    }

    /**
     * 处理解释字段的属性值
     * @param mirrorUpdateAttrDTO
     * @return
     * @throws Exception
     */
    @Override
    public Integer updateMirrorAttr(MirrorUpdateAttrDTO mirrorUpdateAttrDTO) throws XbbException {
        List<Long> formIds = mirrorUpdateAttrDTO.getFormIds();
        String attr = mirrorUpdateAttrDTO.getAttr();
        String subFormAttr = mirrorUpdateAttrDTO.getSubFormAttr();
        Integer operate = mirrorUpdateAttrDTO.getOperate();

        Integer integer;
        try {

            Map<String, Object> params = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
            params.put("formIdIn", formIds);
            params.put(StringConstant.DEL, DelEnum.NORMAL.getDel());
            List<PaasFormExplainEntity> explainList = paasFormExplainModel.findEntitys(params);

            if (explainList.size() < 1) {
                throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, "未查询到数据");
            }

            for (PaasFormExplainEntity explainEntity : explainList) {
                List<FieldAttrEntity> fieldAttrEntities = JSON.parseArray(explainEntity.getExplains(), FieldAttrEntity.class);
                for (FieldAttrEntity attrEntity : fieldAttrEntities) {
                    if (Objects.equals(attrEntity.getAttr(), attr)) {
                        if (Objects.equals(mirrorUpdateAttrDTO.getIsSubForm(), 1)) {
                            if (Objects.isNull(attrEntity.getSubForm())) {
                                throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, "要修改的子表单不存在");
                            }
                            List<? extends FieldAttrEntity> subExplainList = attrEntity.getSubForm().getItems();
                            for (FieldAttrEntity subAttrEntity : subExplainList) {
                                if (Objects.equals(subAttrEntity.getAttr(), subFormAttr)) {
                                    if (Objects.equals(operate, 1)) {
                                        subAttrEntity.setVisible(mirrorUpdateAttrDTO.getVisible());
                                    } else if (Objects.equals(operate, 2)) {
                                        subAttrEntity.setEditable(mirrorUpdateAttrDTO.getEditable());
                                    } else {
                                        subAttrEntity.setVisible(mirrorUpdateAttrDTO.getVisible());
                                        subAttrEntity.setEditable(mirrorUpdateAttrDTO.getEditable());
                                    }
                                }
                            }
                            attrEntity.getSubForm().setItems(subExplainList);
                        } else {
                            if (Objects.equals(operate, 1)) {
                                attrEntity.setVisible(mirrorUpdateAttrDTO.getVisible());
                            } else if (Objects.equals(operate, 2)) {
                                attrEntity.setEditable(mirrorUpdateAttrDTO.getEditable());
                            } else {
                                attrEntity.setVisible(mirrorUpdateAttrDTO.getVisible());
                                attrEntity.setEditable(mirrorUpdateAttrDTO.getEditable());
                            }
                        }
                    }
                }
                explainEntity.setExplains(JSON.toJSONString(fieldAttrEntities));
            }

            integer = paasFormExplainModel.updateBatchExplains(explainList);
        } catch (XbbException e) {
            throw e;
        } catch (Exception e) {
            LOG.error("更新字段error: ", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        return integer;
    }

    /**
     * 删除解释字段里多余属性(仅：可新增，可删除)
     * @param mirrorDeleteAttrDTO
     * @return
     * @throws Exception
     */
    @Override
    public Integer deleteMirrorExtraAttr(MirrorDeleteAttrDTO mirrorDeleteAttrDTO) throws XbbException {

        List<Long> formIds = mirrorDeleteAttrDTO.getFormIds();

        Map<String, Object> params = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        params.put("formIdIn", formIds);
        params.put(StringConstant.DEL, DelEnum.NORMAL.getDel());
        List<PaasFormExplainEntity> explainList = paasFormExplainModel.findEntitys(params);

        if (explainList.size() < 1) {
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, "未查询到数据");
        }

        // 处理字段
        for (PaasFormExplainEntity explainEntity : explainList) {
            JSONArray attrArray = JSONArray.parseArray(explainEntity.getExplains());
            for (Object obj : attrArray) {
                JSONObject jsonObj = (JSONObject) obj;
                String attr = jsonObj.getString("attr");
                boolean flag = Objects.equals(attr, FieldTypeEnum.OWNERID.getAlias()) || Objects.equals(attr, FieldTypeEnum.COUSERID.getAlias());
                if (!flag) {
                    jsonObj.remove("add");
                    jsonObj.remove("addAdvanceEnable");
                    jsonObj.remove("addRule");
                    jsonObj.remove("remove");
                    jsonObj.remove("removeAdvanceEnable");
                    jsonObj.remove("removeRule");
                }
            }
            explainEntity.setExplains(JSON.toJSONString(attrArray));
        }

        // 处理子表单字段
        for (PaasFormExplainEntity explainEntity : explainList) {
            List<FieldAttrEntity> fieldAttrEntities = JSON.parseArray(explainEntity.getExplains(), FieldAttrEntity.class);
            for (FieldAttrEntity fieldAttrEntity : fieldAttrEntities) {
                if (Objects.nonNull(fieldAttrEntity.getSubForm())) {
                    List<? extends FieldAttrEntity> itemArray = fieldAttrEntity.getSubForm().getItems();
                    Iterator<? extends FieldAttrEntity> iterator = itemArray.iterator();
                    while (iterator.hasNext()) {
                        FieldAttrEntity jsonObj = iterator.next();
                        String attr = jsonObj.getAttr();
                        boolean flag = Objects.equals(attr, FieldTypeEnum.OWNERID.getAlias()) || Objects.equals(attr, FieldTypeEnum.COUSERID.getAlias());
                        if (!flag) {
                            jsonObj.setAdd(null);
                            jsonObj.setAddAdvanceEnable(null);
                            jsonObj.setAddRule(null);
                            jsonObj.setRemove(null);
                            jsonObj.setRemoveAdvanceEnable(null);
                            jsonObj.setRemoveRule(null);
                        }
                    }
                    fieldAttrEntity.getSubForm().setItems(itemArray);
                }
            }
            explainEntity.setExplains(JSON.toJSONString(fieldAttrEntities));
        }

        paasFormExplainModel.updateBatchExplains(explainList);

        return explainList.size();
    }

}
